﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;

namespace IService.Handler
{
	/// <summary>
	/// Summary description for UploadHandler
	/// </summary>
	public class UploadHandler : IHttpHandler
	{

		public void ProcessRequest(HttpContext context)
		{
			context.Response.ContentType = "text/plain";
			context.Response.Charset = "utf-8";
			HttpPostedFile file = context.Request.Files["Filedata"];
			string uploadfolder = @context.Request["folder"];
			string uploadPath = HttpContext.Current.Server.MapPath(uploadfolder) + "\\";
			if (file != null)
			{
				if (!Directory.Exists(uploadPath))
				{
					Directory.CreateDirectory(uploadPath);
				}
				string uploadFileName = file.FileName;
				string extend = uploadFileName.Substring(uploadFileName.IndexOf("."));
				string fileName = DateTime.Now.ToFileTime() + extend;
				file.SaveAs(uploadPath + fileName);
				context.Response.Write(uploadfolder + "/" + fileName);
			}
			else
			{
				context.Response.Write("");
			}
		}

		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
	}
}